<template>
  <div class="basic-info">
    <el-form ref="ruleFormRef" :rules="rules" label-width="100px" :model="form">
      <el-form-item label="项目名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入项目名称" />
      </el-form-item>
      <el-form-item label="负责人" prop="people">
        <el-select v-model="form.people" placeholder="请选择负责人">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目周期" prop="program_cycle" style="width:500px">
        <el-date-picker v-model="form.program_cycle" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
          range-separator="到" start-placeholder="开始时间" end-placeholder="结束时间" />
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm(ruleFormRef)">重置</el-button>
        <el-button type="primary" @click="submitForm(ruleFormRef)">下一步</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref, defineEmits } from 'vue'

const ruleFormRef = ref(null)
const emits = defineEmits(['nextStep'])
const form = reactive({
  name: '',
  people: '',
  program_cycle: ''
})

const options = [
  {
    value: 'Option1',
    label: '负责人-1'
  },
  {
    value: 'Option2',
    label: '负责人-2'
  },
  {
    value: 'Option3',
    label: '负责人-3'
  }
]

const rules = reactive({
  name: [
    { required: true, message: '请输入项目名称', trigger: 'blur' }
  ],
  people: [
    { required: true, message: '请选着负责人', trigger: 'change' }
  ],
  program_cycle: [
    { required: true, message: '请输入项目周期', trigger: 'change' }
  ]
})

const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid) => {
    if (valid) {
      emits('nextStep', 1)
    }
  })
}
const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>

<style lang="less" scoped>
.basic-info {
  background-color: #fff;
  margin-top: 10px;
  padding: 20px;
}
</style>
